package student_system.Controller;

import student_system.Dao.studentDao;
import student_system.bean.student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class student_select extends HttpServlet {
    studentDao dao=new studentDao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doPost(req, resp);
        req.setCharacterEncoding("utf-8");
        String sname=req.getParameter("sname");
        if(sname==null){

            List<student> list=dao.testArrayList();
//            for (int i = 0; i < list.size(); i++) {
//                System.out.println(list);
//            }
            req.setAttribute("lists",list);
            RequestDispatcher dispatcher = req.getRequestDispatcher("StudentInfoSelect_3.jsp");
            dispatcher.forward(req,resp);
        }else {
            student student =dao.selectbysname(sname);

            req.setAttribute("ls",student);
            RequestDispatcher dispatcher = req.getRequestDispatcher("student_select.jsp");
            dispatcher.forward(req,resp);
        }


    }
}
